﻿using UnityEngine;
using System.Collections;

public class FinnishLine : MonoBehaviour {

	public ScoreBoard _scoreBoard;
	public int _runnerPoint;
	public WinCondiction _wincondiction;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnTriggerEnter2D(Collider2D other) {

		if (other.gameObject.GetComponent<Jogger> () == null) {
			return;
		}


		Jogger doneJogger = other.gameObject.GetComponent<Jogger> ();


		if (doneJogger.getTeam() == Jogger.YOUR_TEAM) {
			_scoreBoard.addScore(_runnerPoint);
			_wincondiction.joggerFinnished();
		} else if (doneJogger.getTeam() == Jogger.RED_TEAM) {
			_scoreBoard.addScore(-_runnerPoint);

		}
		doneJogger.setNaturalSpeed (0);
		_runnerPoint--;

	}

}
